/**
 * @file   1078.cpp
 * @author Shuang Hu <hsmath@ubuntu>
 * @date   Sat Apr 10 22:11:40 2021
 * 
 * @brief  PAT advanced #1078, make a hash table!
 * 
 * 
 */
#include<iostream>
#include<cmath>
using namespace std;
bool isprime(int c);
int findminprime(int sz);
class Harshtable{
private:
    int elements[10050];
    int size;
public:
    Harshtable(int _size){
	size=findminprime(_size);
	for(int i=0;i<10050;i++){
	    elements[i]=0;
	}
    }
    void Insert(int data);
};
bool isprime(int c){
    if(c==1){
	return false;
    }
    for(int i=2;i<=sqrt(c);i++){
	if(c%i==0){
	    return false;
	}
    }
    return true;
}
int findminprime(int sz){
    int d=sz;
    while(1){
	if(isprime(d)){
	    return d;
	}
	d++;
    }
}
void Harshtable::Insert(int data){
    int pos=data%size;
    for(int step=0;step<size;step++){
	if(elements[pos]==0){
	    elements[pos]=1;
	    cout<<pos;
	    return;
	}else{
	    pos=(pos+2*step+1)%size;
	}
    }
    cout<<"-";
    return;
}
int main(){
    int sz,datanum;
    cin>>sz>>datanum;
    Harshtable HT(sz);
    int data;
    cin>>data;
    HT.Insert(data);
    for(int i=1;i<datanum;i++){
	cin>>data;
	cout<<" ";
	HT.Insert(data);
    }
    cout<<endl;
}
